﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace BDDSynth
{
    public partial class CreateSQL : Form
    {
        SqlConnection cnx;
        
        public CreateSQL()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string cnxStringSQL = "Data Source =METWIN\\SQLEXPRESS;Initial Catalog ='';Integrated Security = true;";
            cnx = new SqlConnection(cnxStringSQL);
            cnx.Open();
            string sqlrequete = "if not exists(select * from sys.databases where name = '"+sqlbasename.Text+"') CREATE DATABASE " + sqlbasename.Text;
            SqlCommand command = new SqlCommand(sqlrequete, cnx);
            command.ExecuteNonQuery();
            cnx.Close();
            string cnxStringSQL2 = "Data Source = METWIN\\SQLEXPRESS;Initial Catalog =" + sqlbasename.Text + ";Integrated Security = true;";
            SqlConnection cnx2;
            cnx2 = new SqlConnection(cnxStringSQL2);
            cnx2.Open();
            string sqlrequete2 = "CREATE TABLE " + sqltablename.Text + "(" + sqlchamp.Text + " " + comboBox1.Text + " , " + sqlcham2.Text + " " + comboBox2.Text + " , " + sqlchamp3.Text + " " + comboBox3.Text + " , " + sqlchamp4.Text + " " + comboBox4.Text + ")";
            SqlCommand command2 = new SqlCommand(sqlrequete2, cnx2);
            command2.ExecuteNonQuery();
            Close();
        }

    }
}
